package com.ruoyi.business.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.business.domain.FreightReceipt;
import com.ruoyi.business.domain.vo.FreightReceiptVo;
import com.ruoyi.common.core.mapper.BaseMapperPlus;

/**
 * 运单回单Mapper接口
 *
 * @author ruoyi
 * @date 2024-04-20
 */
public interface FreightReceiptMapper extends BaseMapperPlus<FreightReceiptMapper, FreightReceipt, FreightReceiptVo> {

    /**
     * 根据运单ID删除回单信息
     *
     * @param freightId 运单id
     * @return
     */
    default boolean deleteByReceiptId(Long freightId) {
        return delete(new LambdaQueryWrapper<FreightReceipt>()
            .eq(FreightReceipt::getFreightId, freightId)
        ) > 0;
    }

    /**
     * 根据运单ID查询回单信息
     *
     * @param waybillId
     * @return
     */
    default FreightReceiptVo selectVoByFreightId(Long waybillId) {
        return selectVoOne(new LambdaQueryWrapper<FreightReceipt>()
            .eq(FreightReceipt::getFreightId, waybillId)
            .last("limit 1"));
    }
}
